<?php
/**
 * 文件上传
 */

namespace app\share\controller;

use think\App;
use think\facade\Request;

class UploadFile
{
    public function __construct()
    {
        $this->upload = new \app\common\model\UploadFile();
    }
    public function uploadFile()
    {
        // 获取表单上传文件
        $file = request()->file("file");
        $folder_name = trim(Request::param("folder_name",""));
        if($file === null)
        {
            returnJson(-2003,"资源不能为空");
        }
        if($folder_name === "")
        {
            returnJson(-2003,"文件夹名称不能为空");
        }
        if( !preg_match("/^[a-zA-Z\s]+$/",$folder_name ))
        {
            returnJson(-2003,"文件夹名称只能由大小写字母组成");
        }

        $data = $this->upload->uploadFile($file,$folder_name);
        returnJson(200,"success",$data);
    }
}